package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import java.time.LocalDate;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Assets;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TLandHouseAssets;
import com.ruoyi.system.domain.TLeaseManage;
import com.ruoyi.system.service.IAssetsService;
import com.ruoyi.system.service.ITHouseAssetsService;
import com.ruoyi.system.service.ITLeaseManageService;
import com.ruoyi.system.vo.LastYearIncomeVo;
import com.ruoyi.system.vo.TLeaseManageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * @author cc
 * @date 2024年04月10日 15:37
 */
@Controller
@RequestMapping("/system/house/analysis")
public class HouseAnalysisController extends BaseController {
    private String prefix = "analysis/house";

    @Autowired
    private ITHouseAssetsService tHouseAssetsService;
    @Autowired
    private ITLeaseManageService leaseManageService;
    @Autowired
    private IAssetsService assetsService;


    @RequiresPermissions("system:house:analysis:view")
    @GetMapping()
    public String house()
    {
        return prefix + "/analysis";
    }

    @RequestMapping("/getAcrge")
    @ResponseBody
    public AjaxResult getAcrge(Assets assets)
    {
        assets.setUrlAdd("house");
        List<Assets> assetsList = assetsService.selectDeptList(assets);
        assetsList.remove(0);
        return success(assetsList);
    }

    /**
     * 查询房产租赁情况数据
     * @param assets
     * @return
     */
    @RequestMapping("/getLeaseAcrge")
    @ResponseBody
    public AjaxResult getLeaseAcrge(Assets assets)
    {
        assets.setUrlAdd("house");
        List<Assets> assetsList = assetsService.selectDeptList(assets);
        assetsList.remove(0);
        return success(assetsList);
    }

    /**
     * 查询房产租赁租金
     * @param leaseManage
     * @return
     */
    @RequestMapping("/getLeaseMoney")
    @ResponseBody
    public AjaxResult getLeaseMoney(TLeaseManage leaseManage)
    {
        String date = DateUtils.getDate();
        List<String> lastYearMonthDate = DateUtils.getLastYearMonthDate();
        List<LastYearIncomeVo> list = new ArrayList<>();
        for (String string : lastYearMonthDate){
            TLeaseManage tLeaseManages = leaseManageService.selectTLeaseManageByTime(string);
        }

        return success(list);
    }

//    @Scheduled(cron = "30 * * * * ?")
//    public void mouthMoney(){
//        TLeaseManageVo tLeaseManageVo = new TLeaseManageVo();
//        List<TLeaseManage> tLeaseManages = leaseManageService.selectTLeaseManageList(new TLeaseManage());
//    }

//    public static void main(String[] args) {
//        LocalDate today = LocalDate.now(); // 获取今天的日期
//        LocalDate startOfYear = today.withDayOfYear(1); // 获取今年的第一天
//        List<Integer> months = new ArrayList<>();
//
//        // 循环直到今年结束，累加已过的月份
//        while (!startOfYear.isAfter(today)) {
//            months.add(startOfYear.getMonthValue());
//            startOfYear = startOfYear.plus(1, ChronoUnit.MONTHS);
//        }
//        System.out.println(months);
//    }

}
